use std::error::Error;

use serde::{Deserialize, Serialize};

use crate::{sql::Table, storage::{engine::Key, Entry}};



pub trait Coding {
    fn encoding(&self) -> Result<Vec<u8>, Box<dyn Error>> where Self: Serialize {
        let seri_value = bincode::serialize(self)?;
        Ok(seri_value) 
    }
    
    fn decoding<'a>(bytes: &'a Vec<u8>) -> Result<Self, Box<dyn Error>> where Self: Deserialize<'a> {
        let deseri_value = bincode::deserialize(bytes)?;
        Ok(deseri_value)
    }
}

impl Coding for Table {}
impl<'a> Coding for Key<'a> {}
impl Coding for Vec<Entry> {}